test(sdk): pin the invariants a reviewer cannot see - #36
Merged
Conversation
Every finding in the 0.12/0.13 batch was two places answering one question, with the surface picking the flattering answer. The leftmost-XFF bug survived in two adapters after the same class was fixed elsewhere, because each call site read perfectly reasonably on its own and nothing connected them. Four source-reading invariants: the client IP is resolved only in client-ip.ts, decisions are only ever built through the Decision class and never spread (a spread silently strips isDenied() and deniedBy()), every starvable rule has a NOT_RUN path, and no node: import reaches a package that ships to Workers. Writing them found two things, which is the point: - The first version flagged detection/detectors/headers.ts, which merely LISTS those header names for suspicious-shape detection. The rule now matches actual access -- headers['x-forwarded-for'] or .get(...) -- not a mention. - It then flagged the Next.js adapter, correctly, for my own code: the x-real-ip and x-vercel-forwarded-for fallbacks I left inline in the trusted-proxy fix were header reads outside the resolver, which is exactly the drift the invariant exists to stop. They now live in resolveClientIp, gated on a declared proxy -- under trustProxy: false we read no forwarding header at all, and X-Real-IP is as forgeable as the rest. Four tests cover the relocated behaviour. 386 core tests, 20/20 turbo tasks, three edge entry points still clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to WebDecoy/app's backend guardrails. Same reasoning: every finding in the 0.12/0.13 batch was two places answering one question, and the leftmost-
X-Forwarded-Forbug survived in two adapters after the same class was fixed elsewhere — because each call site read reasonably on its own and nothing connected them.Four invariants
client-ip.tsDecisionclass, and never spread (a spread silently stripsisDenied()/deniedBy()— the trapprotect()originally fell into)NOT_RUNpath, so "checked and fine" stays distinguishable from "never checked"node:import reaches a package that ships to WorkersWriting them found two things, which is the point
A false positive in my own rule. The first version flagged
detection/detectors/headers.ts, which merely lists those header names for suspicious-shape detection. That is not IP resolution. The rule now matches actual access —headers['x-forwarded-for']or.get(...)— rather than a mention.A real hole in my own fix. It then flagged the Next.js adapter, correctly: the
x-real-ipandx-vercel-forwarded-forfallbacks I left inline during the trusted-proxy work were header reads outside the resolver — exactly the drift the invariant exists to stop, reintroduced by the person who wrote the invariant.They now live inside
resolveClientIp, gated on a declared proxy: undertrustProxy: falsewe read no forwarding header at all, becauseX-Real-IPis as forgeable as the rest. Four new tests cover the relocated behaviour, including that a real forwarding chain still wins over either.Verification
386 core tests, 20/20 turbo tasks, all three edge entry points still compatible.